package com.sujing.webService.servlet;

import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sujing.webService.impl.HelloServiceImpl;

/**
 * Servlet implementation class webServiceDeleteServlet
 */
@WebServlet("/webServiceDeleteServlet")
public class webServiceDeleteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public webServiceDeleteServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see Servlet#init(ServletConfig)
	 */
	public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see Servlet#destroy()
	 */
	public void destroy() {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		System.out.println("..................service().........................");
		String name = request.getParameter("name");
		System.out.println("......name value:............" + name);
		HelloServiceImpl helloServiceI = new HelloServiceImpl();
		if (name!="") {
			String json = helloServiceI.delete(name);
			System.out.println("..............json value:............" + json);
			if (json.equals("{result:0}")) {
				request.getRequestDispatcher("0.jsp").forward(request, response);
			} else if (json.equals("{result:5}")){
				request.getRequestDispatcher("5.jsp").forward(request, response);
			}
		}else{
			request.getRequestDispatcher("noName.jsp").forward(request, response);
		}
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
